import {AfterViewChecked, AfterViewInit, Component, EventEmitter, Input, OnInit, Output} from '@angular/core';
import {HttpService} from "../share/http.service";
import {Router} from "@angular/router";
import {FileInputPluginService} from "../share/file-input-plugin.service";
import {url} from "../share/url";
declare var $: any;
@Component({
  selector: 'app-modal',
  templateUrl: './modal.component.html',
  styleUrls: ['./modal.component.css'],
})
export class ModalComponent implements OnInit, AfterViewInit, AfterViewChecked {
  public produceAddUrl: string = url.url+'/app2/web/manage/product/add';
  public produceUpdataUrl: string = url.url+'/app2/web/manage/product/update';
  public articleAddUrl: string = url.url+'/app2/web/manage/news/add';
  public articleUpdataUrl: string = url.url+'/app2/web/manage/news/update';
  public updataCompanyInfoUrl: string = url.url+'/app2/web/manage/webInfo/update';
  public updataCompanyHtmls: string = url.url+"/app2/web/manage/pagehtml/update";
  public imageUrl: string = url.url+'/';
  public updataTeamAdvantage: string = url.url+'/app2/web/manage/pagehtml/update';
  public updataCareers: string = url.url+'/app2/web/manage/pagehtml/update';
  public imageUploadUrl: string = url.url+'/app2/upload';
  public deleteImageUrl:string = 'http://rapapi.org/mockjsdata/20823/upload/images';
  public showBoolean: boolean = false;
  public fullScreenCheck: boolean = true;
  public fullScreenCheck2: boolean = false;
  public richTextContent: any;
  //用来控制页面是否显示图片上传插件
  public showImageUpload: boolean = false;
  //用来控制显示几个富文本
  public showMultipleBoolean: boolean = false;
  //用来控制富文本编辑内容
  public richText: string;
  //用来控制是否展示第二个上传图片插件
  public showSecondImageUpload: boolean = false;
  //用来控制第一块图片上传的数组
  public unloadImageArray: any = [];
  //用来控制第二块区域的图片
  public unloadImage2Array: any = [];
  //用来控制第一次上传图片时候的数组;
  public firstUnloadImageArray: any = [];
  //从外部导入富文本编辑的内容
  @Input()
  introduceFromText: string;
  //用来控制模态框显示与否
  @Output()
  booleanFromModal: EventEmitter<any> = new EventEmitter();
  //用于控制是显示修改公司还是修改案例的h3标题
  @Input()
  showUniqueTitle: string;
  //从外部导入input里的内容,像标题,服务项目等
  @Input()
  inputValueFromProduce: object;
  //用来控制是否显示图片上传插件
  @Input()
  comeFromShowImageUpload: boolean;
  //用来控制显示用哪种方式上传图片
  @Input()
  httpUrlFromParent: any;
  // //从modal发射出上传图片的id和position
  // @Output()
  // image1DataFromModal: EventEmitter<any> = new EventEmitter();
  // //将当前上传的图片的id与相关需要的内容发射出去
  // @Output()
  // image2DataFromModal: EventEmitter<any> = new EventEmitter();
  //设置显示几个富文本编辑器;
  @Input()
  comeMultipleRichtext: string;
  //设置从外部导入的图片,如果有外部导入的图片的话,
  @Input()
  imagesFromParent: any = [];

  @Input()
  comeFromShowSecondImageUpload: boolean;
//用来控制来自公司介绍页面的信息
  @Input()
  comeFromCompanyDetail: any;
  //用来控制来自团队优势页面
  @Input()
  teamAdvantageFromParent: any;
  //用来控制来自招聘页面
  @Input()
  careeersFromParent: any;

  constructor(private http: HttpService,
              private router: Router,
              private fileInputPlugin: FileInputPluginService) {
  }

  ngAfterViewChecked() {
    // this.richText = this.introduceFromText;
  }

  ngAfterViewInit() {
    // this.richText = this.introduceFromText;
    // setTimeout(() => {
    //   this.richText = this.introduceFromText;
    //   console.log(this.richText)
    // }, 25)
  }

  ngOnInit() {
    setTimeout(() => {
      if(this.showUniqueTitle ==="teamsAdvantage"){
        console.log(12354   );
        let value:any = JSON.parse(this.introduceFromText);
        this.richText =  JSON.stringify(value.pagehtmls[0].htmls[0])
      }else {
        this.richText = this.introduceFromText;
      }
      console.log(this.richText)
    }, 655);
    // console.log(this.imagesFromParent);
    // if (this.imagesFromParent.length>=1) {
    //   console.log("调用image");
    //   this.firstUnloadImageArray.push(this.imagesFromParent[0]);
    // }
    // console.log(this.firstUnloadImageArray);

    //控制图片上传 删除.步骤:第一:从后台获取数据,如果说有图片,且只有一组图片,那么可以判断只有一个上传图片的入口;
    //如果其length>=2的话,说明有2组及以上的图片上传入口,在本项目中,最多为2处上传入口,除了banner处.
    //否则则给this.unloadImageArray与this.unloadImageArray为空,即为新增产品或者新增文章.
    //this.firstUnloadImageArray控制所有的图片,包括已经有的图片数据,和新增的图片数据,目的是为了删除图片数据提供与上传时候的需要
    // setTimeout(() => {
    //
    // }, 100);
    let initalPreviewConfig: any = [];
    let initalPreviewConfig2: any = [];
    // if (this.imagesFromParent && this.imagesFromParent.length === 1) {
    //   // let imgUrl=this.imageUnloadUrl + this.imagesFromParent[0].address;
    //   // let imgName = this.imagesFromParent[0].imgName;
    //   // let imgEle=`<img src='${imgUrl}' class='file-preview-image' alt='${imgName}' title='${imgName}'>`;
    //   // initialPreviewConfig: [
    //   //   {
    //   //     caption: 'desert.jpg',
    //   //     width: '120px',
    //   //     url: 'http://localhost:9080/app2/',// server deleteaction
    //   //     key: 100,
    //   //     extra: {id: 100}
    //   //   }
    //   // ]
    //   // let imgEle = `<img src='${this.imagesFromParent.address}' class='file-preview-image' alt='${this.imagesFromParent.imgName}' title='${this.imagesFromParent.imgName}'>`;
    //   // this.unloadImageArray.push(imgEle);
    //   //
    //   // initalPreviewConfig.push(
    //   //   {
    //   //     caption:this.imagesFromParent.imgName,
    //   //     width:'120px',
    //   //     url:"http://localhost:9080/app2/app2/web/manage/banner/delete",
    //   //     key:100,
    //   //     extra:{id:100}
    //   //   })
    //   this.firstUnloadImageArray = this.firstUnloadImageArray.concat(this.imagesFromParent);
    //   // this.unloadImageArray.push(this.imageUrl + this.imagesFromParent[0].address);
    // } else
    //   if (this.imagesFromParent && this.imagesFromParent.length >= 2) {
    if (this.imagesFromParent.length >= 1) {
      console.log(this.imagesFromParent);
      console.log('有两处需要添加图片的');
      this.firstUnloadImageArray = this.firstUnloadImageArray.concat(this.imagesFromParent);
      console.log(this.firstUnloadImageArray);
      for (let i = 0, len = this.imagesFromParent.length; i < len; i++) {
        // let imgUrl=this.imageUnloadUrl + this.imagesFromParent[i].address;
        // let imgName = this.imagesFromParent[i].imgName;
        // let imgEle=`<img src='${imgUrl}' class='file-preview-image' alt='${imgName}' title='${imgName}'>`;
        // console.log(imgEle);
        let position = this.imagesFromParent[i].position;
        // console.log(position);

        if (position === 'slide' || position === "publicArticle" || position === "companyDetailLeft") {
          let imgEle = `${this.imageUrl}${this.imagesFromParent[i].address}`;
          this.unloadImageArray.push(imgEle);
          //
          initalPreviewConfig.push(
            {
              caption: this.imagesFromParent[i].imgName,
              width: '120px',
              // url:"http://localhost:9080/app2/app2/web/manage/banner/delete",
              url: this.deleteImageUrl,
              key: this.imagesFromParent[i].imgName,
              // extra:{id:100}
            })
          // this.unloadImageArray = this.unloadImageArray.concat(this.imagesFromParent[i])
          // this.unloadImageArray.push(this.imageUrl + this.imagesFromParent[i].address);
        } else {
          // let imgEle = `<img src='http://localhost:9080/app2/${this.imagesFromParent[i].address}' class='file-preview-image' alt='${this.imagesFromParent[i].imgName}' title='${this.imagesFromParent[i].imgName}'>`
          let imgEle = `${this.imageUrl}${this.imagesFromParent[i].address}`;
          this.unloadImage2Array.push(imgEle);
          initalPreviewConfig2.push(
            {
              caption: this.imagesFromParent[i].imgName,
              width: '120px',
              // url:"http://localhost:9080/app2/app2/web/manage/banner/delete",
              url: this.deleteImageUrl,
              key: this.imagesFromParent[i].imgName,
              // extra:{id:100}
            });
          // console.log(initalPreviewConfig2)
          // console.log(this.unloadImage2Array);
          // initalPreviewConfig.push(
          //   {
          //     caption:this.imagesFromParent[i].imgName,
          //     width:'120px',
          //     url:"http://localhost:9080/app2/app2/web/manage/banner/delete",
          //     key:100,
          //     extra:{id:100}
          //   })
          //this.unloadImage2Array = this.unloadImage2Array.concat(this.imagesFromParent);
          // this.unloadImage2Array.push(this.imageUrl + this.imagesFromParent[i].address);
        }
      }
      //
      // this.unloadImageArray=this.imagesFromParent[0];
      // this.unloadImage2Array=this.imagesFromParent[1]
    } else {
      console.log('为新增产品,没有图片');
      this.unloadImageArray = [];
      this.unloadImage2Array = [];
    }
    // console.log(this.unloadImageArray);
    // console.log(initalPreviewConfig);
    this.fileInputPlugin.showFileInputPlugin("#input-gly-1", 10, this.unloadImageArray, initalPreviewConfig);
    this.fileInputPlugin.showFileInputPlugin("#input-gly-2", 5, this.unloadImage2Array, initalPreviewConfig2);
    if (this.comeFromShowImageUpload) {
      this.showImageUpload = this.comeFromShowImageUpload;
    }
    if (this.comeFromShowSecondImageUpload) {
      this.showSecondImageUpload = this.comeFromShowSecondImageUpload;
    }
    //控制显示几个文本输入
    console.log(this.showUniqueTitle);
    if (this.comeMultipleRichtext === 'needOne') {
      this.showMultipleBoolean = false;
    } else {
      this.showMultipleBoolean = true;
    }

    //控制图片
    // $("#input-gly-1").fileinput({
    //   language: 'zh',
    //   theme: "fa",
    //   uploadUrl: "http://localhost:8090/app2/app2/upload",
    //   allowedFileExtensions: ['jpg', 'png', 'gif'],
    //   showClose: false,
    //   // layoutTemplates:false,
    //   maxFileCount: 10,
    //   uploadLabel:'上传',
    //   dropZoneTitle: "可通过拖拽图片放到这里",
    //   browseLabel:'浏览器',
    //   dropZoneClickTitle: "或者点击此区域添加图片",
    //   uploadsync: true,
    //   enctype: 'multipart/form-data',
    //   uploadExtraData: {postiton: "slide"},
    //   msgFilesTooMany: "选择上传的文件数量({n}) 超过允许的最大数值{m}！",
    //   // hideThumbnailContent: true // hide image, pdf, text or other content in the thumbnail preview
    //   overwriteInitial: false,
    //   initialPreviewAsData: true,
    //   initialPreview: [
    //
    //   ],
    //
    // });
    // $("#input-gly-1").on("fileuploaded", function (a, data, c, d) {
    //   console.log("获得数据成功");
    //   let obj:any ={};
    //   console.log(data);
    //   let image1Response = data.response;
    //   obj.path=image1Response.path;
    //   obj.name=data.files[0].name;
    //   obj.position = 'slide';
    //   this.unloadImageArray.push(image1Response);
    //   // this.image1DataFromModal.emit(image1Response)
    // }.bind(this));
    // if(this.showUniqueTitle==='produce'){
    // this.fileInputPluginUploaded("#input-gly-1",'slide');
    // this.fileInputPluginUploaded("#input-gly-2",'slideDown');
    // }
    switch (this.showUniqueTitle) {
      case 'produce':
        this.fileInputPluginUploaded("#input-gly-1", 'slide');
        this.fileInputPluginUploaded("#input-gly-2", 'slideDown');
        break;
      case 'publicArticle':
        this.fileInputPluginUploaded("#input-gly-1", 'publicArticle');
        break;
      case 'companyDetail':
        this.fileInputPluginUploaded("#input-gly-1", 'companyDetailLeft');
        this.fileInputPluginUploaded("#input-gly-2", 'companyDetailRight');
        break;
      case 'teamsAdvantage':
        // this.fileInputPluginUploaded("#input-gly-1", 'teamsAdvantageLeft');
        // this.fileInputPluginUploaded("#input-gly-2", 'teamsAdvantageRight');
        break;
    }

    // $("#input-gly-1").on("filesuccessremove", function (event, data, id, index) {
    //   let deleteName = $('#' + data + ' img').attr('title');
    //   console.log(deleteName);
    //   console.log(this.firstUnloadImageArray);
    //   // this.firstUnloadImageArray = this.firstUnloadImageArray.filter((item)=>item.imgName === deleteName);
    //   for (let i = 0, len = this.firstUnloadImageArray.length; i < len; i++) {
    //     if (this.firstUnloadImageArray[i].imgName === deleteName) {
    //       this.firstUnloadImageArray.splice(i, 1);
    //     }
    //   }
    //   // event.preventDefault();
    //   // console.log(index)
    //   console.log(this.firstUnloadImageArray)
    // }.bind(this));
    this.fileInputPluginDelete("#input-gly-1");
    this.fileInputPluginDelete("#input-gly-2");
    this.fileInputPluginPredelete("#input-gly-1");
    this.fileInputPluginPredelete("#input-gly-2");
    // $("#input-gly-1").on("filedeleteerror", function (event, data, id, index) {
    //   // let deleteName = $('#'+data+' img').attr('title');
    //   // console.log(this.firstUnloadImageArray);
    //   // for(let i=0,len=this.firstUnloadImageArray.length;i<len;i++){
    //   //   if(this.firstUnloadImageArray[i].imgName === deleteName){
    //   //     delete this.firstUnloadImageArray[i]
    //   //   }
    //   // }
    //   // console.log(this.firstUnloadImageArray)
    //   // console.log('删除文件')
    //   // event.preventDefault();
    //   // console.log(index)
    // }.bind(this));
    // $("#input-gly-1").on("filecleared",function ( data) {
    //   console.log(2);
    //   // console.log(event);
    //   console.log(data);
    //   // console.log(previewId);
    //   // console.log(index)
    // })
    // $("#input-gly-1").on("filereset",function ( data) {
    //   console.log(3);
    //   // console.log(event);
    //   console.log(data);
    //   // console.log(previewId);
    //   // console.log(index)
    // })
    // $("#input-gly-1").on("fileerror",function ( data) {
    //   console.log(4);
    //   // console.log(event);
    //   console.log(data);
    //   // console.log(previewId);
    //   // console.log(index)
    // })
    // $("#input-gly-2").on("fileuploaded", function (a, data, c, d) {
    //   console.log("获得数据成功");
    //   let obj:any=[];
    //   let image2Response = data.response;
    //   // this.image2DataFromModal.emit(image2Response);
    //   console.log(image2Response)
    // }.bind(this));


    // $('#input-gly-1').on('filepredelete', function(event, key, jqXHR, data) {
    //   console.log(key);
    //   for(let i =0,len = this.firstUnloadImageArray.length;i<len;i++){
    //     if(this.firstUnloadImageArray[i].imgName ===key){
    //       this.firstUnloadImageArray.splice(i,1)
    //     }
    //   }
    //   console.log(this.firstUnloadImageArray);
    // }.bind(this));
  }

  // modifyCompany(){
  //   this.showBoolean = !this.showBoolean
  // }

  fileInputPluginPredelete(ele) {
    $(ele).on("filepredelete", function (event, key, jqXHR, data) {
      console.log(this.firstUnloadImageArray);
      console.log(key);
      // let j:number;
      for (let i = 0, len = this.firstUnloadImageArray.length; i < len; i++) {
        let pName = this.firstUnloadImageArray[i].imgName;
        console.log(pName);
        if (pName === key) {
          // console.log(i);
          // j = i;
          this.firstUnloadImageArray.splice(i, 1);
          return;
        }
      }
      // this.firstUnloadImageArray.splice(j,1);
    }.bind(this))
  }

  fileInputPluginDelete(ele) {
    $(ele).on('filesuccessremove', function (event, data, id, index) {
      console.log(data);
      let deleteName = $('#' + data + ' img').attr('title');
      console.log(deleteName);
      let newArray = [];
      // this.firstUnloadImageArray = this.firstUnloadImageArray.filter((item)=>item.imgName === deleteName);
      for (let i = 0, len = this.firstUnloadImageArray.length; i < len; i++) {
        if (this.firstUnloadImageArray[i].imgName === deleteName) {
          this.firstUnloadImageArray.splice(i, 1);
        }
      }
      console.log(this.firstUnloadImageArray);
      // event.preventDefault();
      // console.log(index)
    }.bind(this))
  }


  fileInputPluginUploaded(ele, position) {
    $(ele).on("fileuploaded", function (a, data, c, d) {
      console.log("成功上传图片,获取数据");
      // console.log(data);
      // console.log(a);
      // console.log(c);
      // console.log(d);
      let obj: any = {};
      let image1Response = data.response;
      console.log(data);
      let pName: string = '';
      let files = data.files;
      console.log(files);
      for (let i = 0, len = files.length; i < len; i++) {
        if (files[i] !== 'undefined') {
          console.log(files[i]);
          pName = files[i].name;
          break;
        }
      }
      obj.address = image1Response.results.path;
      obj.imgName = pName;
      obj.position = position;
      this.firstUnloadImageArray.push(obj);
      // this.unloadImageArray.push(obj);
      console.log(this.firstUnloadImageArray);
      // this.image1DataFromModal.emit(image1Response)
    }.bind(this));
  }

  closeAddPro() {
    this.booleanFromModal.emit(this.showBoolean)
  }

  comeFromRichText(event) {
    console.log(event);
    this.richTextContent = event;
  }


  onSubmit() {
    if (this.inputValueFromProduce && this.showUniqueTitle === 'produce') {
      console.log("发布产品页面");
      console.log(this.httpUrlFromParent);
      let richTextHtmls: any;
      //如果说有来自父亲的富文本内容，要么为编辑案例页面，否则的话就为新增
      //this.richTextContent用来保存新数据，infoFromParent 用来保存从父组件过来的原始数据
      if (this.introduceFromText) {
        // 用于保存富文本编辑器内容
        let infoFromParent = JSON.parse(this.introduceFromText);
        console.log(infoFromParent);
        richTextHtmls = infoFromParent;
        console.log(this.richTextContent === undefined);
        if (this.richTextContent == undefined) {
          console.log("啥都没改");
          richTextHtmls = infoFromParent
        } else if (this.richTextContent !== undefined && this.richTextContent.left !== undefined && this.richTextContent.left === '') {
          console.log("修改右侧");
          richTextHtmls[1].html = this.richTextContent.right;
          // richTextHtmls =[{html:infoFromParent.html,position:infoFromParent.position},{html:this.richTextContent.right,position:"right"}]
        } else if (this.richTextContent !== undefined && this.richTextContent.right !== undefined && this.richTextContent.right === '') {
          console.log("修改左侧");
          richTextHtmls[0].html = this.richTextContent.left;
          // richTextHtmls =[{html:this.richTextContent.left,position:"left"},{html:infoFromParent.html,position:infoFromParent.position}]
        } else {
          console.log("修改两处了");
          richTextHtmls[0].html = this.richTextContent.left;
          richTextHtmls[1].html = this.richTextContent.right;
          // richTextHtmls = [{html:infoFromParent[0].html,position:'left'},{html:infoFromParent[1].html,position:'right'}]
        }
        console.log(richTextHtmls);
      } else {
        richTextHtmls = [{html: this.richTextContent.left, position: 'left'}, {
          html: this.richTextContent.right,
          position: 'right'
        }]
      }
      Object.assign(this.inputValueFromProduce, this.richTextContent);
      let inputValue: any = this.inputValueFromProduce;
      console.log(inputValue);
      let inputValueService = inputValue.serviceDir.meeting + "|" + inputValue.serviceDir.service;
      console.log(inputValueService);
      // let obj = {
      //   catagoryId: inputValue.catagoryId,
      //   homeFlag: inputValue.showIndexWhehter,
      //   htmls: [{html: inputValue.left, position: 'left'}, {html: inputValue.right, position: 'right'}],
      //   images: this.firstUnloadImageArray,
      //   proName: inputValue.title,
      //   title: inputValueService
      // };
      let obj: any = {};
      if (inputValue.id) {
        obj = {
          catagoryId: inputValue.catagoryId,
          homeFlag: inputValue.showIndexWhehter,
          htmls: richTextHtmls,
          images: this.firstUnloadImageArray,
          proName: inputValue.title,
          title: inputValueService,
          id: inputValue.id
        }
      } else {
        obj = {
          catagoryId: inputValue.catagoryId,
          homeFlag: inputValue.showIndexWhehter,
          htmls: richTextHtmls,
          images: this.firstUnloadImageArray,
          proName: inputValue.title,
          title: inputValueService
        }
      }

      if (this.httpUrlFromParent.httpPost) {
        console.log("调用httpPost请求,来自modal");
        this.http.httpPost(this.produceAddUrl, obj)
          .subscribe(res => {
            console.log(res)
          });
      } else if (this.httpUrlFromParent.httpPut) {
        console.log('调用httpPut请求,来自modal');
        this.http.httpPut(this.produceUpdataUrl, obj)
          .subscribe(res => {
            console.log(res);
            alert("更新成功，请刷新浏览器")
          })
      }
    } else if (this.inputValueFromProduce && this.showUniqueTitle === 'publicArticle') {
      console.log("发布文章页面");
      Object.assign(this.inputValueFromProduce, this.richTextContent);
      let inputValue: any = this.inputValueFromProduce;

      let richTextHtmls: any;
      //如果有来自父组件的富文本数据，则判断有没有来自富文本编辑器里的数据，如果有，则把其数据重新给obj，传给服务器
      if (this.introduceFromText) {
        let infoFromParent = JSON.parse(this.introduceFromText);
        console.log(infoFromParent);
        richTextHtmls = infoFromParent;
        // console.log(this.richTextContent === undefined);
        if (this.richTextContent == undefined) {
          console.log("啥都没改");
          richTextHtmls = infoFromParent
        } else {
          console.log("修改一处了");
          richTextHtmls.html = this.richTextContent.left;
          // richTextHtmls[1].html = this.richTextContent.right;
          // richTextHtmls = [{html:infoFromParent[0].html,position:'left'},{html:infoFromParent[1].html,position:'right'}]
        }
      }else{
        richTextHtmls = {html:this.richTextContent.left}
      }


      let date = new Date();
      let obj: any = {
        content: inputValue.newsDir,
        htmls: [richTextHtmls],
        images: this.firstUnloadImageArray,
        newsTime: date.getTime(),
        title: inputValue.articleTitle
      };
      console.log(obj);
      if (this.httpUrlFromParent.httpPost) {
        this.http.httpPost(this.articleAddUrl, obj)
          .subscribe(res => {
            console.log(res);
            alert("添加成功")
          })
      } else if (this.httpUrlFromParent.httpPut) {
        obj.id = inputValue.catagoryId;
        // obj.images = this.firstUnloadImageArray.push(this.imagesFromParent);
        console.log(this.firstUnloadImageArray);
        console.log(this.imagesFromParent);
        console.log(obj);
        this.http.httpPut(this.articleUpdataUrl, obj)
          .subscribe((res) => {
            console.log(res);
            alert("更新成功,请刷新浏览器")
          })
      }
    } else if (this.inputValueFromProduce && this.showUniqueTitle === 'companyDetail') {
      console.log('调用公司更新页面');
      let inputValue: any = this.inputValueFromProduce;
      this.http.httpPut(this.updataCompanyInfoUrl, inputValue)
        .subscribe((res) => {
          console.log(res);
          // alert("info更新成功");
        });
      console.log(this.unloadImageArray);
      let infoFromParent = JSON.parse(this.introduceFromText);
      console.log(infoFromParent);
      let htmls: any;
      console.log(this.comeFromCompanyDetail);
      console.log(this.richTextContent);
      if (this.richTextContent) {
        console.log("富文本内容变动了");
        let richTextLeft: string, richTextRight: string;
        if (this.richTextContent.right === "") {
          richTextRight = infoFromParent[0].html
        } else {
          richTextRight = this.richTextContent.right
        }
        if (this.richTextContent.left === "") {
          richTextLeft = infoFromParent[1].html
        } else {
          richTextLeft = this.richTextContent.left
        }
        // console.log(this.firstUnloadImageArray);
        htmls = {
          id: this.comeFromCompanyDetail.id,
          page: this.comeFromCompanyDetail.page,
          title: this.comeFromCompanyDetail.title,
          htmls: [{html:richTextRight, position: 'left', id: this.comeFromCompanyDetail.htmls[0].id},
            {html:richTextLeft, position: 'right', id: this.comeFromCompanyDetail.htmls[1].id}],
          // images: this.firstUnloadImageArray
        };
        debugger;
        console.log(htmls)
      } else {
        console.log("富文本内容没有变动");
        let value = JSON.parse(this.introduceFromText);
        htmls = this.comeFromCompanyDetail
        // htmls = {
        //   id: value.id,
        //   htmls: [{html: value[0].html, position: 'left'},
        //     {html: value[1].html, position: 'right'}],
        //   images: this.unloadImageArray
        // };
        // console.log(htmls)
        // this.richText.right = value[0].html;
        // this.richText.left = value[1].html;

      }
      htmls.images = this.firstUnloadImageArray;
      console.log(htmls);
      this.http.httpPut(this.updataCompanyHtmls, htmls)
        .subscribe((res) => {
          alert("更新成功");
          console.log("htmls更新成功");
        })
    } else if (this.showUniqueTitle === 'teamsAdvantage') {
      console.log("调用团队优势");
      console.log(this.introduceFromText);
      console.log(this.richTextContent);
      // console.log(this.richTextContent);
      // console.log(this.teamAdvantageFromParent);
      let htmls :any = JSON.parse(this.introduceFromText);
      // this.
      // if (this.richTextContent && this.richTextContent.left && this.richTextContent.left === "") {
      //   // htmls = this.teamAdvantageFromParent;
      // } else {
      //   htmls.html = this.richTextContent.left
      // }
      if(this.richTextContent !== undefined){
        console.log("富文本内容更新了");
        htmls.pagehtmls[0].htmls[0].html = this.richTextContent.left
      }
      console.log(htmls);
      this.http.httpPut(this.updataTeamAdvantage, htmls.pagehtmls[0])
        .subscribe((res) => {
          console.log(res)
        })
    } else if (this.showUniqueTitle === 'careers') {
      console.log("调用招聘页面");
      let htmls = this.careeersFromParent;
      if (this.richTextContent) {
        htmls.htmls[0].html = this.richTextContent.left
      }
      this.http.httpPut(this.updataCareers, htmls)
        .subscribe((res) => {
          console.log("招聘页面更新成功");
          alert("更新成功,请刷新浏览器");
        });
      console.log(this.careeersFromParent);
    }
    this.booleanFromModal.emit(this.showBoolean);
    // this.router.navigate(['/index/produce']);
  }

  //设置是否全屏展示
  fullScreen() {
    if (this.fullScreenCheck) {
      $(".publicArticle").css({
        padding: 0
      })
    } else {
      $(".publicArticle").css({
        padding: "3%"
      })
    }
    this.fullScreenCheck = !this.fullScreenCheck
    this.fullScreenCheck2 = !this.fullScreenCheck2
  }


  // showFileInputPlugin(ele, maxFileCount, uploadExtraData, initalPreviewConfig,initalPreviewCon) {
  //   $(ele).fileinput({
  //     language: 'zh',
  //     theme: "fa",
  //     uploadUrl: this.imageUploadUrl,
  //     // uploadUrl: "http://rapapi.org/mockjsdata/20823/upload/images",
  //     allowedFileExtensions: ['jpg', 'png', 'gif'],
  //     showClose: false,
  //     // layoutTemplates:false,
  //     maxFileCount: maxFileCount,
  //     uploadLabel: '上传',
  //     cancelLabel: '取消',
  //     msgFileRequired: '您必须选择一个文件上传',
  //     msgUploadEnd: '完成',
  //     dropZoneTitle: "可通过拖拽图片放到这里",
  //     browseLabel: '浏览器',
  //     dropZoneClickTitle: "或者点击此区域添加图片",
  //     uploadsync: true,
  //     enctype: 'multipart/form-data',
  //     uploadExtraData: {postiton: uploadExtraData},
  //     msgUploadThreshold: '上传中...',
  //     msgUploadEmpty: '没有图片上传.',
  //     msgFilesTooMany: "选择上传的文件数量({n}) 超过允许的最大数值{m}！",
  //     msgLoading: '正在上传{index} of {files} &hellip;',
  //     msgProgress: '上传进度: {index} 的 {files} - {name} - {percent}%.',
  //     msgFileNotFound: '文件 "{name}" 没有找到!',
  //     msgInvalidFileType: '无效的类型 "{name}". 只有 "{types}" 类型文件是支持的.',
  //     msgUploadBegin: '开始上传...',
  //     msgAjaxError: '{operation} 过程中出错了. 请稍后尝试,或者联系我们!',
  //     msgAjaxProgressError: '{operation} 失败!',
  //     ajaxOperations: {
  //       deleteThumb: '删除图片',
  //       uploadThumb: '上传图片',
  //       uploadBatch: 'batch file upload',
  //       uploadExtra: 'form data upload'
  //     },
  //     // hideThumbnailContent: true // hide image, pdf, text or other content in the thumbnail preview
  //     overwriteInitial: false,
  //     initialPreviewAsData: true,
  //     // initialPreview: initalPreviewConfig,
  //     initialPreview:
  //     initalPreviewConfig
  //     // `<img src='/images/desert.jpg' class='file-preview-image' alt='Desert' title='Desert'>`,
  //     ,
  //     initialPreviewConfig:initalPreviewCon
  //     // initialPreviewConfig: [
  //     //   {
  //     //     caption: 'desert.jpg',
  //     //     width: '120px',
  //     //     url: 'http://localhost:9080/app2/',// server deleteaction
  //     //     key: 100,
  //     //     extra: {id: 100}
  //     //   }
  //     // ]
  //   });
  // }

}
